package com.share.rules.controller;

import com.share.common.core.domain.Result;
import com.share.common.core.web.controller.BaseController;
import com.share.common.security.annotation.InnerAuth;
import com.share.rules.domain.FeeRule;
import com.share.rules.domain.FeeRuleRequestForm;
import com.share.rules.domain.FeeRuleResponseVo;
import com.share.rules.service.IFeeRuleService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 费用规则controller
 */
@RestController
@RequestMapping("/feeRule")
@Slf4j
public class FeeRuleController extends BaseController {

    @Autowired
    private IFeeRuleService feeRuleService;

    @Operation(summary = "批量获取费用规则信息")
    @PostMapping(value = "/getFeeRuleList")
    public Result<List<FeeRule>> getFeeRuleList(@RequestBody List<Long> feeRuleIds){
        log.info("批量获取费用规则信息:{}",feeRuleIds);

        //mp
        List<FeeRule> feeRules = feeRuleService.listByIds(feeRuleIds);

        return Result.ok(feeRules);
    }

    @Operation(summary = "获取费用规则详细信息")
    @GetMapping(value = "/getFeeRule/{id}")
    public Result<FeeRule> getFeeRule(@PathVariable Long id){
        log.info("获取费用规则详细信息:{}",id);

        //mp
        FeeRule feeRule = feeRuleService.getById(id);
        return Result.ok(feeRule);
    }

    //通过规则引擎 计算订单费用
    @Operation(summary = "计算订单费用")
    @PostMapping("/calculateOrderFee")
    public Result<FeeRuleResponseVo> calculateOrderFee(@RequestBody FeeRuleRequestForm calculateOrderFeeForm) {
        return Result.ok(feeRuleService.calculateOrderFee(calculateOrderFeeForm));
    }
}
